import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:爱吃素
 * User: wangxin
 * Date: 2024-10-06
 * Time: 21:02
 */
public class test1 {
    public static boolean isNum(long c){

        if(c < 2){
            return false;
        }
        for(long i = 2;i <= Math.sqrt(c); i++){
            if(c % i == 0){
                return false;
            }
        }
        return true;
    }
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别

        int T = in.nextInt();
        for(int i = 0;i < T;i++){
            long a = in.nextLong();
            long b = in.nextLong();
            if(a > 1&&b > 1){
                System.out.println("NO");
            }else if(a == 1&&isNum(b)){
                System.out.println("YES");

            }else if(b == 1&& isNum(a)){
                System.out.println("YES");
            }else{
                System.out.println("NO");

            }

        }

    }
}
